<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{$Think.config.site.title} - 主页</title>
    <meta name="keywords" content="{$Think.config.site.keywords}">
    <meta name="description" content="{$Think.config.site.description}">
    <link href="{$Think.config.site.resource_url}css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/animate.css" rel="stylesheet">    
    <link href="{$Think.config.site.resource_url}css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/style.css?v=4.1.0" rel="stylesheet">
    <style>
        #listtable .fa{    cursor: pointer;color: #1ab394;margin-right: 1em;}
    </style>
</head>

<body >
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
            <style type="text/css">.col-sm-12 label{ font-weight:300; }</style>
                <div class="ibox float-e-margins">
                    <div class="">
                        <h5>商户列表</h5>
                    </div>
                    <div class="row ibox-title">
                    <form action="" method="post" name="leaseorder">
                        <label><button type="button"  class="btn btn-sm btn-primary" id="addBtn"> 添加商户</button>　　</label>
                        <label >商铺名称：</label>
                        <label ><input type="text" class="input-sm form-control" name="name" value="{$name ?? ''}"  aria-controls="" placeholder="输入商铺名称"></label>　　 　　　 　　 
                        <label>所在区域：</label>
                        <label ><input type="text" class="input-sm form-control" name="area" value="{$area ?? ''}" aria-controls="" placeholder="输入所在区域"></label><label><button type="submit" class="btn btn-sm btn-primary"> 提交</button> </label> 
                        </form>
                    </div>
                    <div class="ibox-content">

                        <table class="table table-hover" id="listtable">
                            <thead>
                                <tr>
                                    <th>店铺图片</th>
                                    <th>商铺名称</th>
                                    <th>业务员</th>
                                    <th>电话</th>
                                    <th>人均消费</th>
                                    <th>所在区域</th>
                                    <th>详细地址</th>
                                    <th>营业时间</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                            {volist name="list" id="v"}
                            <?php
                                    if(strlen($v['shopstart'])==1){
                                        $start =  '0'.$v['shopstart'].':00';
                                    }else if(strlen($v['shopstart'])==2){
                                        $start =  $v['shopstart'].':00';        
                                    }else if(strlen($v['shopstart'])==3){
                                        $start =  '0'.$v['shopstart'];
                                        $start=insertToStr($start, 2, ":");
                                    }else if(strlen($v['shopstart'])==4){
                                        $start =  $v['shopstart'];
                                        $start=insertToStr($start, 2, ":");
                                    }

                                    if(strlen($v['shopend'])==1){
                                        $end =  '0'.$v['shopend'].':00';
                                    }else if(strlen($v['shopend'])==2){
                                        $end =  $v['shopend'].':00';        
                                    }else if(strlen($v['shopend'])==3){
                                        $end =  '0'.$v['shopend'];
                                        $end=insertToStr($end, 2, ":");
                                    }
                                    else if(strlen($v['shopend'])==4){
                                        $end =  $v['shopend'];
                                        $end=insertToStr($end, 2, ":");
                                    }

                                ?>
                                <tr data-id="{$v.id}">
                                    <td>{if condition="$v['picture'] neq ''"} <img src="{$Think.config.resourceurl,$v.picture}" alt=""width="30" height="30">{else /} <img src="{$Think.config.site.resource_url}images/timg.jpg" alt=""width="30" height="30"> {/if}</td>
                                    <td>{$v.name}</td>
                                    <td>{$v.username}</td>
                                    <td>{$v.phone}</td>
                                    <td>{$v.averageprice}</td>
                                    <td>{$v.area}</td>
                                    <td>{$v.addr}</td>
                                    <td>{$start}~{$end}</td>
                                    <td><i class="fa fa-edit"> 修改</i> <i class="fa fa-battery-1"> 设备详情 </i> <i class="fa fa-trash-o"> 删除</i> </td>
                                </tr> 
                            {/volist}
                            </tbody>
                        </table>
                    </div>

                    <div class="row">
                        <div class="row">
                        <div class="col-sm-5">
                            <div class="dataTables_info" id="DataTables_Table_0_info" role="alert" aria-live="polite" aria-relevant="all"></div>
                        </div>
                        <div class="col-sm-7">
                            <div class="dataTables_paginate paging_simple_numbers" id="DataTables_Table_0_paginate">
                                {$list->render()}
                            </div>
                        </div>
                    </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
    <script src="{$Think.config.site.resource_url}js/jquery.min.js?v=2.1.4"></script>
    <script src="{$Think.config.site.resource_url}js/bootstrap.min.js?v=3.3.5"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/peity/jquery.peity.min.js"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/iCheck/icheck.min.js"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/layer/layer.js"></script>

    <script>

    var layer_font;
    var $editTr;
        $(document).ready(function() {
            $("#addBtn").bind("click",function(){
                layer_font = layer.open({
                  type: 2,
                  title: '添加商户信息',
                  shadeClose: true,
                  shade: 0.8,
                  area: ['35%', '90%'],
                  content: '<?php echo \think\Request::instance()->root(); ?>/ausagent/Seller/add' //iframe的url
                });
            });

            //修改按钮
            $("#listtable").on("click",".fa-edit",function(){
                $editTr = $(this).closest("tr");
                var id = $editTr.data("id");
                layer_font = layer.open({
                  type: 2,
                  title: '修改商户信息',
                  shadeClose: true,
                  shade: 0.8,
                  area: ['35%', '90%'],
                  content: '<?php echo \think\Request::instance()->root(); ?>/ausagent/Seller/edit?id='+id //iframe的url
                });
            })

            //设备详情
            $("#listtable").on("click",".fa-battery-1",function(){
                $editTr = $(this).closest("tr");
                var id = $editTr.data("id");
                layer_font = layer.open({
                  type: 2,
                  title: '查看设备信息',
                  shadeClose: true,
                  shade: 0.8,
                  area: ['80%', '90%'],
                  content: '<?php echo \think\Request::instance()->root(); ?>/ausagent/Equipment/index?sid='+id //iframe的url
                });
            })
            
            //删除按钮注册
            $("#listtable").on("click",".fa-trash-o",function(){
                var $tr = $(this).closest("tr");
                var id = $tr.data("id");
                layer.confirm('确定要删除？', {
                    btn: ['确定删除','不删除'], //按钮
                    shade: false //不显示遮罩
                }, function(){
                    //确定删除
                    $.ajax({
                        type : 'POST',//delete
                        url : '<?php echo \think\Request::instance()->root(); ?>/ausagent/Seller/delete?id='+id,
                        dataType : 'json',
                        data : {id:id},
                        async:false,
                        success : function(result) {
                            //layer.close(layer1);
                            if(0 === result.code) {
                                $tr.remove();
                                layer.msg(result.msg, {icon: 1});
                            }  else  {
                                //删除失败
                                layer.msg(result.msg, {icon: 5});
                            }
                        },
                        error : function(){
                            res = false;
                            layer.msg('服务器错误！请稍后重试', {icon: 2});
                        }
                    })
                },
                function(){
                    
                });

                
            });
        }); 
    </script>
    <!--统计代码，可删除-->

</body>

</html>
